home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-04 | 21.4 KB | 1,111 lines | [TEXT/MPS ] |
- /*
- File: WindowObj.h
-
- Contains: Windows for a simple Scriptable application.
-
- Developed by:
-
- Paul G Smith (commstalk hq & Full Moon Software, Inc)
-
- you can leave messages at (UK): 0727 844232; (US): 408 253 7199
- BUT I prefer to be contacted by e-mail
- AppleLink: SMITH.PG
- Internet: SMITH.PG@applelink.apple.com
-
- "SimpliFace" Sample code to accompany develop article
- on techniques for embedding scripts in applications.
-
- */
-
-
- #ifndef __STDIO__
- #include <StdIO.h>
- #endif
-
- #ifndef __WINDOWOBJ__
- #include "WindowObj.h"
- #endif
-
- #ifndef __SimpliFaceCOMMON__
- #include "SimpliFaceCommon.h"
- #endif
-
- #ifndef __APPLICATIONCOMMON__
- #include "ApplicationCommon.h"
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
- #ifndef __FILES__
- #include <Files.h>
- #endif
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
- #ifndef __SYSEQU__
- #include <SysEqu.h>
- #endif
- #ifndef __PLSTRINGFUNCS__
- #include <PLStringFuncs.h>
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef __AERegistry__
- #include <AERegistry.h>
- #endif
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef __AEOBJECTPACKING__
- #include <AEPackObject.h>
- #endif
-
- #ifndef __AEOMTOKENS__
- #include "ObjModelTokens.h"
- #endif
- #ifndef __AEOMEVENTS__
- #include "ObjModelEvents.h"
- #endif
-
- #ifndef __SCRIPTUTILS__
- #include "ScriptUtils.h"
- #endif
-
-
-
- /**********************************************************************
- ** PUBLIC Constructor
- ***********************************************************************/
-
- // when window object is first created, no window is opened;
- // (unless the window property 'visible' is initially true)
- // the window record is created and actually opened the first
- // time the window receives an 'open' event or is made 'visible'
-
- TWindowObj::TWindowObj()
- {
- InitFields();
- fInitialized = true;
- }
-
- TWindowObj::TWindowObj(const AEDesc *theData)
- {
- InitFields();
- SetData(theData);
- fInitialized = true;
- }
-
- TWindowObj::~TWindowObj()
- {
- TListOfLongs aList = fButtonElems; // makes temporary copy of list
- long numElems = aList.CountElements();
- while (numElems > 0)
- {
- delete (TInterfaceObj*)(aList.GetElement(numElems));
- numElems--;
- }
- aList = fFieldElems;
- numElems = aList.CountElements();
- while (numElems > 0)
- {
- delete (TInterfaceObj*)(aList.GetElement(numElems));
- numElems--;
- }
- fButtonElems.SetData(NULL);
- fFieldElems.SetData(NULL);
-
- if (fWindowPtr)
- {
- CloseWindow(fWindowPtr);
- fWindowPtr = NULL;
- }
- }
-
- void TWindowObj::InitFields(void)
- {
- fInitialized = false;
- fBounds.left = 100;
- fBounds.top = 100;
- fBounds.right = 200;
- fBounds.bottom = 200;
- fHasCloseBox = true;
- fHasTitleBar = true;
- fIsModal = false;
- fIsResizable = false;
- fIsZoomable = false;
- fIsZoomed = false;
- fName = "";
- fShouldBeVisible = false;
- fHasBeenCreated = false;
- fWindowDefProc = documentProc;
- fWindowPtr = NULL;
- fButtonElems.SetData(NULL);
- fFieldElems.SetData(NULL);
- }
-
-
- void TWindowObj::ActivateWindow(Boolean isActivating)
- {
- }
-
-
- void TWindowObj::UpdateWindow(void)
- {
- if (fWindowPtr)
- {
- SetPort(fWindowPtr);
- BeginUpdate(fWindowPtr);
- DrawWindow();
- EndUpdate(fWindowPtr);
- }
- }
-
-
- void TWindowObj::DrawAllElements(DescType desiredClass)
- {
- if (fWindowPtr)
- {
- TListOfLongs aList; // makes temporary copy of list
-
- if (desiredClass == cButton)
- aList = fButtonElems;
- else if (desiredClass == cTextField)
- aList = fFieldElems;
-
- long numElems = aList.CountElements();
- while (numElems > 0)
- {
- TInterfaceObj* anElement = (TInterfaceObj*)(aList.GetElement(numElems));
- if (anElement)
- anElement->DrawObject();
- numElems--;
- }
- }
- }
-
-
- void TWindowObj::DrawWindow(void)
- {
- if (fWindowPtr)
- {
- DrawAllElements(cTextField);
- DrawAllElements(cButton);
- }
- }
-
-
- /**********************************************************************
- ** PUBLIC AE Object Model support
- ***********************************************************************/
-
-
- OSErr TWindowObj::CountElements(DescType desiredClass, long *result)
- {
- OSErr err = errAEEventNotHandled;
-
- if (desiredClass == cButton)
- {
- *result = fButtonElems.CountElements();
- err = 0;
- }
- else if (desiredClass == cTextField)
- {
- *result = fFieldElems.CountElements();
- err = 0;
- }
- return err;
- }
-
-
- OSErr TWindowObj::CreateNewElement (DescType desiredClass,
- DescType position,
- AEDesc *theData,
- AERecord *theProperties,
- TScriptableObject *theContainerObj,
- TScriptableObject **theNewObj)
- {
- OSErr err = errAEEventNotHandled;
- TInterfaceObj *newInterfaceObj = NULL;
-
- if (desiredClass == cButton)
- {
- if (theProperties)
- newInterfaceObj = new TButtonObj(this, theProperties);
- else
- {
- newInterfaceObj = new TButtonObj(this);
- if (newInterfaceObj && theData)
- newInterfaceObj->SetProperty(pName, theData);
- }
- }
- else if (desiredClass == cTextField)
- {
- if (theProperties)
- newInterfaceObj = new TLabelObj(this, theProperties);
- else
- {
- newInterfaceObj = new TLabelObj(this);
- if (newInterfaceObj && theData)
- newInterfaceObj->SetProperty(pName, theData);
- }
- }
-
- if (newInterfaceObj)
- {
- if (desiredClass == cButton)
- fButtonElems.InsertElement((long)newInterfaceObj);
- else
- fFieldElems.InsertElement((long)newInterfaceObj);
- *theNewObj = newInterfaceObj;
- err = 0;
- }
-
- return err;
- }
-
-
- OSErr TWindowObj::ResolveContainer(TScriptableObject **theContainerObj)
- {
- OSErr err = 0;
-
- *theContainerObj = gSimpliFace;
-
- return err;
- }
-
-
- OSErr TWindowObj::ResolveElementByName(DescType desiredClass,
- CStr255& nameStr,
- TScriptableObject **theResultObj)
- {
- OSErr err = errAEEventNotHandled;
- TInterfaceObj *anObj = NULL;
- CStr255 aName;
- TListOfLongs aList; // makes temporary copy of list
-
- if (desiredClass == cButton)
- aList = fButtonElems;
- else if (desiredClass == cTextField)
- aList = fFieldElems;
- else
- return err;
-
- long numElems = aList.CountElements();
- while (numElems > 0)
- {
- anObj = (TInterfaceObj*)(aList.GetElement(numElems));
- if (anObj)
- {
- anObj->GetName(aName);
- if (aName == nameStr)
- {
- *theResultObj = anObj;
- numElems = 0;
- err = 0;
- }
- }
- numElems--;
- }
-
- return err;
- }
-
-
- OSErr TWindowObj::ResolveElementByIndex(DescType desiredClass,
- short theIndex,
- TScriptableObject **theResultObj)
- {
- OSErr err = errAEEventNotHandled;
- TInterfaceObj *anObj = NULL;
- CStr255 aName;
- TListOfLongs aList; // makes temporary copy of list
- short index = theIndex;
-
- if (desiredClass == cButton)
- aList = fButtonElems;
- else if (desiredClass == cTextField)
- aList = fFieldElems;
- else
- return err;
-
- if (index<0)
- {
- short numElems = (short)aList.CountElements();
- index = numElems+index+1;
- }
-
- *theResultObj = (TInterfaceObj*)(aList.GetElement(index));
- if (*theResultObj != NULL)
- err = 0;
-
- return err;
- }
-
-
-
- OSErr TWindowObj::OpenObject(void)
- {
- OSErr err = 0;
- Boolean isVisible = false;
-
- if (fWindowPtr)
- isVisible = ((WindowPeek)fWindowPtr)->visible;
-
- if (fInitialized && !isVisible)
- {
- fShouldBeVisible = true;
- if (!fWindowPtr)
- {
- Rect theBounds = fBounds;
- CStr255 theName = fName;
-
- fWindowPtr = NewWindow(NULL, &theBounds, theName,
- false, fWindowDefProc, WindowPtr(-1),
- fHasCloseBox, (long)this);
-
- }
- if (fWindowPtr)
- {
- ShowWindow(fWindowPtr);
- }
- }
-
- printf("TWindowObj::OpenObject(): err = %d\n", err);
- return err;
- }
-
- OSErr TWindowObj::CloseObject(void)
- {
- OSErr err = 0;
- Boolean isVisible = false;
-
- if (fWindowPtr)
- isVisible = ((WindowPeek)fWindowPtr)->visible;
- if (fInitialized && isVisible)
- {
- fShouldBeVisible = false;
- if (fWindowPtr)
- {
- HideWindow(fWindowPtr);
- }
- }
-
- return err;
- }
-
- OSErr TWindowObj::GetProperty (DescType propertyID, DescType wantType, AEDesc *result)
- {
- OSErr err = errAEEventNotHandled;
- Boolean theBoolean;
-
- switch (propertyID)
- {
- case pBounds:
- Rect theRect = fBounds;
- if (fWindowPtr)
- theRect = (*((WindowPeek)fWindowPtr)->strucRgn)->rgnBBox;
- err = AECreateDesc(typeQDRectangle, (Ptr)&theRect,
- sizeof(theRect), result);
- break;
- case pName:
- {
- CStr255 theName = fName;
- err = AECreateDesc(typeChar, (Ptr)&theName[1],
- theName.Length(), result);
- }
- break;
- case pHasCloseBox:
- theBoolean = fHasCloseBox;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- case pHasTitleBar:
- theBoolean = fHasTitleBar;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- case pIsModal:
- theBoolean = fIsModal;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- case pIsResizable:
- theBoolean = fIsResizable;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- case pIsZoomable:
- theBoolean = fIsZoomable;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- case pIsZoomed:
- theBoolean = fIsZoomed;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- case pIndex:
- short theIndex = 0;
- if (fWindowPtr)
- {
- do
- theIndex++;
- while (fWindowPtr != GetWindowPtrOfNthWindow(theIndex));
- }
- err = AECreateDesc(typeShortInteger, (Ptr)&theIndex,
- sizeof(theIndex), result);
- break;
- case pVisible:
- theBoolean = false;
- if (fWindowPtr)
- theBoolean = ((WindowPeek)fWindowPtr)->visible;
- err = AECreateDesc(typeBoolean, (Ptr)&theBoolean,
- sizeof(theBoolean), result);
- break;
- default:
- err = TScriptableObject::GetProperty(propertyID, wantType, result);
- break;
- }
-
- return err;
- }
-
- OSErr TWindowObj::SetProperty (DescType propertyID, const AEDesc *theData)
- {
- OSErr err = errAEEventNotHandled;
-
- if (fWindowPtr && (propertyID == pHasCloseBox ||
- propertyID == pHasTitleBar ||
- propertyID == pIsModal ||
- propertyID == pIsResizable ||
- propertyID == pIsZoomable))
- return errAENotModifiable;
-
- switch (propertyID)
- {
- case pBounds:
- {
- Rect newBounds;
- err = GetRectFromDescriptor(theData, &newBounds);
- if (!err)
- {
- fBounds = newBounds;
- if (fInitialized && fWindowPtr)
- {
- MoveWindow(fWindowPtr, newBounds.left, newBounds.top, false);
- SizeWindow(fWindowPtr, newBounds.right-newBounds.left,
- newBounds.bottom-newBounds.top, true);
- }
- }
- }
- break;
- case pName:
- {
- CStr255 theName;
- err = GetCStringFromDescriptor(theData, &theName);
- if (!err)
- {
- fName = theName;
- if (fInitialized && fWindowPtr)
- SetWTitle(fWindowPtr, (ConstStr255Param) theName);
- }
- }
- break;
- case pVisible:
- Boolean theBoolean = false;
- err = GetBooleanFromDescriptor(theData, &theBoolean);
- if (!err)
- {
- fShouldBeVisible = theBoolean;
- if (fInitialized)
- {
- if (fShouldBeVisible)
- OpenObject();
- else
- CloseObject();
- }
- }
- break;
- default:
- err = TScriptableObject::SetProperty(propertyID, theData);
- break;
- }
-
- return err;
- }
-
-
-
- OSErr TWindowObj::GetObjectSpecifier (AEDesc *result)
- {
- // walk along containment hierarchy & build object specifier
- //
- // top container is null container
- // then remainder are the object classes specified by name
- //
- OSErr err = 0;
- AEDesc containerDesc, newContainerDesc;
-
- err = MakeNullDesc(&containerDesc);
- if (!err)
- {
- AEDesc nameDesc;
-
- err = MakeNameDesc(fName, &nameDesc);
- if (!err)
- {
- err = CreateObjSpecifier(cWindow, &containerDesc, formName,
- &nameDesc, true, &newContainerDesc);
- containerDesc = newContainerDesc;
- }
- }
-
- *result = containerDesc;
-
- return err;
- }
-
-
- TScriptableObject* TWindowObj::FindElement(Point& thePt, DescType desiredClass)
- {
- TListOfLongs aList; // makes temporary copy of list
-
- if (desiredClass == cButton)
- aList = fButtonElems;
- else if (desiredClass == cTextField)
- aList = fFieldElems;
-
- long numElems = aList.CountElements();
- while (numElems > 0)
- {
- TInterfaceObj* anElement = (TInterfaceObj*)(aList.GetElement(numElems));
- if (anElement)
- {
- Rect theBounds;
-
- anElement->GetBounds(theBounds);
-
- if (PtInRect(thePt, &theBounds))
- return anElement;
- }
- numElems--;
- }
- return NULL;
- }
-
-
- OSErr TWindowObj::GetTargetObjectSpecifier (EventRecord& theEvent, AEDesc *result)
- {
- OSErr err = 0;
- AEDesc containerDesc;
-
- if (theEvent.what == mouseDown)
- {
- Point clickPt = theEvent.where;
-
- GlobalToLocal(&clickPt);
-
- TInterfaceObj* theElement = (TInterfaceObj*)FindElement(clickPt, cButton);
- if (!theElement)
- theElement = (TInterfaceObj*)FindElement(clickPt, cTextField);
-
- if (theElement)
- err = theElement->GetObjectSpecifier(&containerDesc);
- else
- err = GetObjectSpecifier(&containerDesc);
- }
- else
- err = GetObjectSpecifier(&containerDesc);
-
- *result = containerDesc;
-
- return err;
- }
-
-
-
- /**********************************************************************
- ** PUBLIC Constructor
- ***********************************************************************/
-
- TInterfaceObj::TInterfaceObj(TWindowObj* container)
- {
- fContainer = container;
- InitFields();
- fInitialized = true;
- }
-
- TInterfaceObj::TInterfaceObj(TWindowObj* container, const AEDesc *theData)
- {
- fContainer = container;
- InitFields();
- SetData(theData);
- fInitialized = true;
- }
-
- TInterfaceObj::~TInterfaceObj()
- {
- }
-
- void TInterfaceObj::InitFields(void)
- {
- Str255 fontName;
-
- fInitialized = false;
- fBounds.left = 0;
- fBounds.top = 0;
- fBounds.right = 0;
- fBounds.bottom = 0;
- GetFontName(applFont, fontName);
- fFontName = fontName;
- fName = "";
- fFontSize = 12;
- fFontStyle = 0;
- fFgColor.red = 0xFFFF;
- fFgColor.green = 0xFFFF;
- fFgColor.blue = 0xFFFF;
- }
-
-
- DescType TInterfaceObj::GetClass(void)
- {
- return typeNull;
- }
-
-
- void TInterfaceObj::DrawObject(void)
- {
- }
-
-
- void TInterfaceObj::ForceRedrawObject(Boolean drawNow)
- {
- if (drawNow)
- DrawObject();
- else
- {
- Rect theBounds = fBounds;
- InvalRect(&theBounds);
- }
- }
-
-
- OSErr TInterfaceObj::ResolveContainer(TScriptableObject **theContainerObj)
- {
- OSErr err = 0;
-
- *theContainerObj = fContainer;
-
- return err;
- }
-
-
- OSErr TInterfaceObj::GetProperty (DescType propertyID, DescType wantType, AEDesc *result)
- {
- OSErr err = errAEEventNotHandled;
-
- switch (propertyID)
- {
- case pBounds:
- {
- Rect theRect = fBounds;
- err = AECreateDesc(typeQDRectangle, (Ptr)&theRect,
- sizeof(theRect), result);
- }
- break;
- case pPointSize:
- {
- short theNum = fFontSize;
- err = AECreateDesc(typeShortInteger, (Ptr)&theNum,
- sizeof(theNum), result);
- }
- break;
- case pFont:
- {
- CStr255 theName = fFontName;
- err = AECreateDesc(typeChar, (Ptr)&theName[1],
- theName.Length(), result);
- }
- break;
- case pName:
- {
- CStr255 theName = fName;
- err = AECreateDesc(typeChar, (Ptr)&theName[1],
- theName.Length(), result);
- }
- break;
- default:
- err = TScriptableObject::GetProperty(propertyID, wantType, result);
- break;
- }
-
- return err;
- }
-
- OSErr TInterfaceObj::SetProperty (DescType propertyID, const AEDesc *theData)
- {
- OSErr err = errAEEventNotHandled;
-
- switch (propertyID)
- {
- case pBounds:
- {
- Rect newBounds;
- err = GetRectFromDescriptor(theData, &newBounds);
- if (!err)
- {
- ForceRedrawObject(false);
- fBounds = newBounds;
- ForceRedrawObject(false);
- }
- }
- break;
- case pFont:
- {
- CStr255 theName;
- err = GetCStringFromDescriptor(theData, &theName);
- if (!err)
- {
- fFontName = theName;
- ForceRedrawObject(false);
- }
- }
- break;
- case pName:
- {
- CStr255 theName;
- err = GetCStringFromDescriptor(theData, &theName);
- if (!err)
- {
- fName = theName;
- ForceRedrawObject(false);
- }
- }
- break;
- case pPointSize:
- {
- short theNum = 0;
- err = GetIntegerFromDescriptor(theData, &theNum);
- if (!err)
- {
- fFontSize = theNum;
- ForceRedrawObject(false);
- }
- }
- break;
- default:
- err = TScriptableObject::SetProperty(propertyID, theData);
- break;
- }
-
- return err;
- }
-
-
-
-
- OSErr TInterfaceObj::GetObjectSpecifier (AEDesc *result)
- {
- // walk along containment hierarchy & build object specifier
- //
- // top container is null container
- // then remainder are the object classes specified by name
- //
- OSErr err = 0;
- AEDesc containerDesc, newContainerDesc;
-
- err = fContainer->GetObjectSpecifier(&containerDesc);
- if (!err)
- {
- AEDesc nameDesc;
-
- err = MakeNameDesc(fName, &nameDesc);
- if (!err)
- {
- err = CreateObjSpecifier(GetClass(), &containerDesc, formName,
- &nameDesc, true, &newContainerDesc);
- containerDesc = newContainerDesc;
- }
- }
-
- *result = containerDesc;
-
- return err;
- }
-
-
-
-
- /**********************************************************************
- ** PUBLIC Constructor
- ***********************************************************************/
-
- TLabelObj::TLabelObj(TWindowObj* container) : TInterfaceObj (container)
- {
- InitFields();
- }
-
- TLabelObj::TLabelObj(TWindowObj* container,
- const AEDesc *theData) : TInterfaceObj (container)
- {
- InitFields();
- SetData(theData);
- }
-
- TLabelObj::~TLabelObj()
- {
- if (fContents)
- DisposHandle(fContents);
- }
-
-
- void TLabelObj::InitFields(void)
- {
- fContents = NULL;
- }
-
-
- DescType TLabelObj::GetClass(void)
- {
- return cTextField;
- }
-
-
- void TLabelObj::DrawObject(void)
- {
- Handle datah = fContents;
-
- if (fInitialized && datah)
- {
- Rect theBounds = fBounds;
-
- InsetRect(&theBounds, 3, 3); // standard 3pt inset for text fields
-
- if (!EmptyRect(&theBounds))
- {
- HLock(datah);
- TextBox(StripAddress((Ptr)(*datah)), GetHandleSize(datah),
- &theBounds, teJustLeft);
- HUnlock(datah);
- }
- }
- }
-
-
- void TLabelObj::ForceRedrawObject(Boolean drawNow)
- {
- TInterfaceObj::ForceRedrawObject(drawNow);
- }
-
-
-
- OSErr TLabelObj::GetProperty (DescType propertyID, DescType wantType, AEDesc *result)
- {
- OSErr err = errAEEventNotHandled;
-
- switch (propertyID)
- {
- case pContents:
- Handle h = fContents;
- err = HandToHand(&h);
- if (!err)
- {
- result->descriptorType = typeChar;
- result->dataHandle = h;
- }
- break;
- default:
- err = TInterfaceObj::GetProperty(propertyID, wantType, result);
- break;
- }
-
- return err;
- }
-
- OSErr TLabelObj::SetProperty (DescType propertyID, const AEDesc *theData)
- {
- OSAError err = errAEEventNotHandled;
-
- switch (propertyID)
- {
- case pContents:
- {
- AEDesc displayData;
- OSAID valueID = kOSANullScript;
-
- err = OSACoerceFromDesc(gScriptingComponent, theData,
- kOSAModeNull, &valueID);
-
- if (!err && valueID != kOSANullScript)
- err = OSADisplay(gScriptingComponent, valueID,
- typeChar, kOSAModeDisplayForHumans,
- &displayData);
-
- OSADispose(gScriptingComponent, valueID);
-
- if (!err && displayData.dataHandle)
- {
- Handle h = displayData.dataHandle;
- err = HandToHand(&h);
- if (fContents)
- DisposHandle(fContents);
- fContents = h;
- AEDisposeDesc(&displayData);
- ForceRedrawObject(false);
- }
- else
- printf("Failed to set contents of field: err=%ld\n", err);
- }
- break;
- default:
- err = TInterfaceObj::SetProperty(propertyID, theData);
- break;
- }
-
- return (OSErr)err;
- }
-
-
- /**********************************************************************
- ** PUBLIC Constructor
- ***********************************************************************/
-
- TButtonObj::TButtonObj(TWindowObj* container) : TInterfaceObj (container)
- {
- InitFields();
- }
-
- TButtonObj::TButtonObj(TWindowObj* container,
- const AEDesc *theData) : TInterfaceObj (container)
- {
- InitFields();
- SetData(theData);
- }
-
- TButtonObj::~TButtonObj()
- {
- if (fControlH)
- DisposeControl(fControlH);
- }
-
- void TButtonObj::InitFields(void)
- {
- TInterfaceObj::InitFields();
-
- fButtonKind = kAEBtnStandard;
- fControlH = NULL;
- }
-
-
- DescType TButtonObj::GetClass(void)
- {
- return cButton;
- }
-
-
- void TButtonObj::DrawObject(void)
- {
- if (!fControlH)
- {
- // create the button
- Rect theBounds = fBounds;
- CStr255 title = fName;
- short theProcID = pushButProc; // assume standard by default
- WindowPtr theWindow = fContainer->GetWindowPtr();
-
- if (fButtonKind == kAEBtnCheckbox)
- theProcID = checkBoxProc;
- else if (fButtonKind == kAEBtnCheckbox)
- theProcID = radioButProc;
-
- fControlH = NewControl(theWindow, &theBounds, title, true,
- 0, 0, 1, theProcID, (long)this);
- }
- if (fControlH)
- Draw1Control(fControlH);
- }
-
-
- void TButtonObj::ForceRedrawObject(Boolean drawNow)
- {
- TInterfaceObj::ForceRedrawObject(drawNow);
- }
-
-
- OSErr TButtonObj::GetProperty (DescType propertyID, DescType wantType, AEDesc *result)
- {
- OSErr err = errAEEventNotHandled;
-
- switch (propertyID)
- {
- case pButtonKind:
- DescType theKind = fButtonKind;
- err = AECreateDesc(typeType, (Ptr)&theKind, sizeof(theKind), result);
- break;
- default:
- err = TInterfaceObj::GetProperty(propertyID, wantType, result);
- break;
- }
-
- return err;
- }
-
- OSErr TButtonObj::SetProperty (DescType propertyID, const AEDesc *theData)
- {
- OSErr err = errAEEventNotHandled;
-
- switch (propertyID)
- {
- case pBounds:
- err = TInterfaceObj::SetProperty(propertyID, theData);
- if (!err && fControlH)
- {
- Rect newBounds = fBounds;
- MoveControl(fControlH, newBounds.left, newBounds.top);
- SizeControl(fControlH, newBounds.right-newBounds.left,
- newBounds.bottom-newBounds.top);
- }
- break;
- case pButtonKind:
- DescType theKind;
- err = GetDescTypeFromDescriptor(theData, &theKind);
- if (!err)
- fButtonKind = theKind;
- break;
- default:
- err = TInterfaceObj::SetProperty(propertyID, theData);
- break;
- }
-
- return err;
- }
-